﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ymatou.Counter.Contract;
using Ymatou.ServiceCenter;

namespace Coments.Service
{
    public class CounterService
    {
        public static Dictionary<string, Dictionary<string, int>> GetGroupCounterList(string counter, List<string> targetIds)
        {
            GetGroupCounterListRequest request = new GetGroupCounterListRequest()
            {
                AppId = ConfigHelper.CounterAppId,
                Counter = counter,
                TargetIds = targetIds
            };

            var response = ServiceClient.Execute<GetGroupCounterListRequest, GetGroupCounterListResponse>(request);
            if (response != null && response.Code == StatusCode.Success)
            {
                return response.Data;
            }
            return null;
        }

        public static Dictionary<string, Dictionary<string, int>> SetGroupCounterList(string counter, List<string> targetIds, int value = 1)
        {
            SetGroupCounterListRequest request = new SetGroupCounterListRequest()
            {
                AppId = ConfigHelper.CounterAppId,
                Counter = counter,
                TargetIds = targetIds,
                Action = value == 1 ? CounterAction.Increase : CounterAction.Set,
                Value = value
            };

            var response = ServiceClient.Execute<SetGroupCounterListRequest, SetGroupCounterListResponse>(request);
            if (response != null && response.Code == StatusCode.Success)
            {
                return response.Data;
            }
            return null;
        }
    }
}
